package com.ihcy.base.model.entity;

import com.ihcy.base.enums.OrderTypeEnum;
import com.ihcy.base.enums.convert.OrderTypeEnumJpaConvert;
import lombok.*;
import org.hibernate.annotations.Proxy;
import org.hibernate.annotations.Type;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import java.time.LocalDateTime;

@Entity
@EntityListeners(AuditingEntityListener.class) // 配合 @CreatedDate  @LastModifiedDate
@Table(name = "t_order")
@org.hibernate.annotations.Table(appliesTo = "t_order", comment = "订单表")
@Getter
@Setter
@Proxy(lazy = false)
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class Order {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id", nullable = false)
    private Long id;

    @Column(nullable = false, unique = true, columnDefinition = "varchar(10) comment '员工编号'")
    private String orderNo;

    private String address;

    @Convert(converter = OrderTypeEnumJpaConvert.class)
    @Column(nullable = false)
    private OrderTypeEnum orderType;

    @Column
    @Type(type = "yes_no")
    private Boolean isDeleted = Boolean.FALSE;

    @CreatedDate
    @Column(updatable = false)
    private LocalDateTime createdTime;
    @LastModifiedDate
    private LocalDateTime updatedTime;

    @Override
    public String toString() {
        return "Order{" +
                "id=" + id +
                ", orderNo='" + orderNo + '\'' +
                ", address='" + address + '\'' +
                ", orderType=" + orderType +
                ", isDeleted=" + isDeleted +
                ", createdTime=" + createdTime +
                ", updatedTime=" + updatedTime +
                '}';
    }
}
